package worldinruin.file.imp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import worldinruin.core.IMap;
import worldinruin.file.IFile;

public class File implements IFile {
	
	private MapHandler mapHandler = MapHandler.getInstance();	
	private static IFile instance;
	
	/**
	 * Creates a single instance of File.
	 */
	private File(){}
	
	/**
	 * Gets the single instance of File.
	 * @return Single instance of File.
	 */
	public static IFile getInstance(){
		
		if(instance == null){
			instance = new File();
		}
		
		return instance;
	}

	@Override
	public IMap loadMap(String filename) {
		return mapHandler.loadMap(filename);
	}

	@Override
	public void saveMap(String filename, IMap map) {
		mapHandler.saveMap(filename, map);		
	}

	@Override
	public ArrayList<IMap> getMaps() {
		return mapHandler.getMaps();
	}
	
	@Override
	public Set<String> getMapNames() {
		return mapHandler.getMapNames();
	}
	
	@Override
	public IMap getMap(String mapName) {
		return mapHandler.getMap(mapName);
	}
	
	@Override
	public void savePlayerNames(List<String> playerNames){
		try {
			Settings.savePlayerNames(playerNames);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public List<String> loadPlayerNames(){
		return Settings.loadPlayerNames();
	}

}
